<template>
  <template v-for="menu in userMenu">
    <el-submenu
      v-if="
        menu.children &&
        menu.children.length > 0 &&
        menu.children[0].type == null
      "
      :key="menu.id"
      :index="menu.id">

      <template #title>
         <i :class="menu.icon"></i>
        <span>{{ menu.name }}</span>
      </template>

      <tree-menu :userMenu="menu.children" />
    </el-submenu>

    <el-menu-item
      v-else-if="menu.type == null"
      :index="menu.href"
      :key="menu.id">

      <template #title>
        <span>{{ menu.name }}</span>
      </template>

    </el-menu-item>
  </template>
</template>
<script>
export default {
  name: "TreeMenu",
  props: {
    userMenu: {
      type: Array,
      default() {
        return [];
      },
    },
  },
};
</script>